﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Globalization;

namespace LinearAlgebra
{
    public partial class OrthagonalBasisDialog : Form
    {
        public OrthagonalBasisDialog(float v1, float v2)
        {
            InitializeComponent();

            V1_1.Text = v1.ToString("0.00", CultureInfo.InvariantCulture);
            V2_1.Text = v2.ToString("0.00", CultureInfo.InvariantCulture);

            V1_2.Text = v1.ToString("0.00", CultureInfo.InvariantCulture);
            V2_2.Text = v2.ToString("0.00", CultureInfo.InvariantCulture);            

            EqTerm1.Text = v1.ToString("0.00", CultureInfo.InvariantCulture) + " x ";
            EqTerm2.Text = v2.ToString("0.00", CultureInfo.InvariantCulture) + " y ";

            float termOne = v1;
            float termTwo = v2;

            if(termOne == 0)
            {
                termOne = 1;
                termTwo = 0;
            }
            else if(termTwo == 0)
            {
                termOne = 0;
                termTwo = 1;
            }
            else if(termOne > termTwo )
            {
                termOne /= -termTwo;
                termTwo = 1;
            }
            else
            {
                termTwo /= -termOne;
                termOne = 1;
            }

            Ratio1.Text = termOne.ToString("0.00", CultureInfo.InvariantCulture) + "x";
            Ratio2.Text = termTwo.ToString("0.00", CultureInfo.InvariantCulture) + "y";

            OrthoX.Text = termOne.ToString("0.00", CultureInfo.InvariantCulture);
            OrthoY.Text = termTwo.ToString("0.00", CultureInfo.InvariantCulture);

            float mag1 = (float)Math.Sqrt(v1*v1 + v2*v2);            
            float mag2 = (float)Math.Sqrt(termOne*termOne + termTwo*termTwo);

            Mag1.Text = mag1.ToString("0.00", CultureInfo.InvariantCulture);
            Mag2.Text = mag2.ToString("0.00", CultureInfo.InvariantCulture);

            ResultX1.Text = (v1/mag1).ToString("0.00", CultureInfo.InvariantCulture);
            ResultY1.Text = (v2/mag1).ToString("0.00", CultureInfo.InvariantCulture);

            ResultX2.Text = (termOne/mag2).ToString("0.00", CultureInfo.InvariantCulture);
            ResultY2.Text = (termTwo/mag2).ToString("0.00", CultureInfo.InvariantCulture);
        }

        private void button5_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}
